home *** CD-ROM | disk | FTP | other *** search
- /*
- CDTrackTime - An XFCN to report time of a track
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDTrackTime.c
- link -sn Main=CDTrackTime -sn STDIO=CDTrackTime ∂
- -sn INTENV=CDTrackTime -rt XFCN=42 ∂
- -m CDTrackTime CDTrackTime.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDTrackTime
- *
- * Purpose: return the length of a track.
- *
- * Returns: either 0, or an error
- * if it's a negative number, it's an error
- *
- * Side Effects:
- *
- * Description: We need no parameter:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global
- * call the driver with a READQ call to find out
- * how absolute minute, second, block remaining.
- *
- ************************************************************************/
- pascal void
- CDTrackTime(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- long Remaining[3]; /* minute, second, block */
- long endMinute, endSecond, endBlock;
- long startMinute, startSecond, startBlock;
- long trackNo;
-
- /* Must be one parameter, or no parameters */
- if ((paramPtr->paramCount) > 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
-
- /* If we were passed a track number, use it instead of the current track */
- if ((paramPtr->paramCount) == 1)
- trackNo = atoi((char *)*(paramPtr->params[0]));
- else
- result = ReadQ(ioRefNum, &trackNo, &startMinute, &startSecond, &startBlock);
-
- result = TrackStart(ioRefNum, trackNo, &startMinute, &startSecond, &startBlock);
-
- if (result == noErr)
- result = TrackStart(ioRefNum, trackNo+1, &endMinute, &endSecond, &endBlock);
-
- if (result != noErr) /* we specified an invalid track. Use disc time */
- result = DiscTime(ioRefNum, &endMinute, &endSecond, &endBlock);
-
- if (result == noErr)
- {
- TimeDiff(&Remaining[0], &Remaining[1], &Remaining[2],
- endMinute, endSecond, endBlock,
- startMinute, startSecond, startBlock);
- }
-
- if (result == noErr)
- {
- /* convert each value to a string, concatenate, & return. */
- FormatString(&returnString, Remaining, 3);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-